package com.bw.android.bwgao6week2a;

import android.content.Intent;

import com.bw.android.bwgao6week2a.databinding.ActivityMainBinding;
import com.bw.ch.baselib.BaseBindingActivity;

import java.util.concurrent.TimeUnit;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;

public class MainActivity extends BaseBindingActivity<ActivityMainBinding> {
    private Disposable mDisposable;
    /**
     * 倒计时时长，单位：秒
     */
    public static final long launcherCounter = 1;

    @Override
    public int getLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        mDisposable = Flowable.intervalRange(0, launcherCounter, 0, 1, TimeUnit.SECONDS)
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {
                    }
                }).doOnComplete(new Action() {
                    @Override
                    public void run() throws Exception {
                        startActivity(new Intent(MainActivity.this, HomeActivity.class));
                    }
                }).subscribe();
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mDisposable != null) mDisposable.dispose();
    }
}